<?php
$_SESSION['hallpass'] = true;
include "DBConnection.php";
require_once "./Objects/User.php";
require_once "security.php";
include "simple_html_dom.php";

//require "referer.php";
 
$flag = session_start();

//if($flag==true)
	//echo "<p> <b> Cannot start session </b> </p>";	
	
$connection = new Connection(); //connect to the DB
	
//Retrieving language selections
getlang();
//Retrieving education selections
getedu();

function getedu() {
	
	$email = mysql_real_escape_string($_SESSION['email']);

	
	//$connection = new Connection(); //connect to the DB

	//Retrieving education selections
	$html = file_get_html("../HTML/resworker.php");
	$edutable = $html->find('#edutable');
	$count = count($edutable);
	echo $count;
	
	foreach($html->find('#edutable tr') as $row) {
		$cells = $row->find('td');
		$degree = cells(0)->innertext;
		$institue = cells(1)->innertext;
		$field = cells(2)->innertext;
		
		$query=mysql_real_escape_string("INSERT INTO workertrack.worker-education (w_email, edc_level, institute, field) VALUES ('$email','$degree','$institute', '$field')");
		echo $query;	
		$connection->execute_query($query);
	}
	
//	$file_html = file_get_contents("../HTML/resworker.php");
	
	
	
/*	
	$flag = 1; //Skipping title row
	foreach($edutable as $row) {
		
		echo $row;
		if($flag==1)
			$flag=0;
		else {
			echo $row;
			$degree = $row->find('td', 0)->plaintext;
			$field = $row->find('td', 1)->plaintext;
			$institute = $row->find('td', 2)->plaintext;
 
 
	
			$query=mysql_real_escape_string("INSERT INTO workertrack.worker-education (w_email, edc_level, institute, field) VALUES ('$email','$degree','$institute', '$field')");	
			$connection->execute_query($query);
		}

	}
 * 
 */

	
}

function getlang() {
	
	$email = $_SESSION['email'];
	$connection = new Connection(); //connect to the DB
	
	// Retrieving language selections
	$langchkboxes = $_POST['langchkboxes'];
	if(isset($langchkboxes)) {
		
		foreach($langchkboxes as $langchkbox) {
			
			if($langchkbox=="eng") {		
				$level = $_POST['encombobox'];
				$lang = "English";
			}	
			else if($langchkbox=="heb") {
				$level = $_POST['hecombobox'];
				$lang = "Hebrew";
			}		
			else if($langchkbox=="fr") {
				$level = $_POST['frcombobox'];
				$lang = "French";
			}	
			else if($langchkbox=="ru") {
				$level = $_POST['rucombobox'];
				$lang = "Russian";
			}		
			else if($langchkbox=="ar") {
				$level = $_POST['arcombobox'];
				$lang = "Arabic";
			}	
			else if($langchkbox=="ot") {
				$level = $_POST['otcombobox'];
				$lang = "Other";
			}
			
			$query = "SELECT lang_id FROM workertrack.languages WHERE language = '$lang'";
			$resultSet = $connection->execute_query($query);																
			$lang_id = mysql_result($resultSet, 0);
			
			$query="INSERT INTO workertrack.worker_lang (w_email, lang_id, level) VALUES ('$email','$lang_id','$level')";	
			$connection->execute_query($query);
		}
	} // End languages selections
}


$connection->close_connection();


//For development - continuing without spoof security and e-mail confirm
//header('Location: ../HTML/paypal.php');
$_SESSION['hallpass'] = false;
?>